import $http from '../../plugins/MyHttp'
export default {
    namespaced: true,
    state: {
        equipment: null,
        // loop_list: null,
        lamp_list: null,
        MeteorologicalList: null,
        PacketLoopID: "",
        groupLoopList: [],
        pages: 1,
        groupLoopList2: null,
        total: 0,
        d_search: "",
        Distinguish: true,
        Identification: '',
        mount: '设备控制',
        imcType: "",
        distribution: ''
    },
    mutations: {
        loop_groupList(state, res) {
            state.equipment = res
                // state.loop_list = res.loop
                // state.lamp_list = res.lamp
        },
        // 接收点击传来组的id
        PacketLoop(state, res) {
            state.PacketLoopID = res[0]
            state.imcType = Number(res[1])
            console.log(state.imcType)
        },
        // 回路得数据
        resLoopList(state, res) {
            state.groupLoopList = res
        },
        removeLoopList(state, res) {
            state.groupLoopList = []

        },
        page(state, res) {
            state.pages = res
        },
        resLoopList2(state, res) {
            state.groupLoopList2 = res
        },
        total(state, res) {
            state.total = res
        },
        //   每次请求之后都要把分页还原
        setPage(state) {
            state.pages = 1
        },
        // 电箱搜索
        search(state, res) {
            state.d_search = res;
        },
        del_search(state, res) {
            state.d_search = "";
        },
        // 到了功能选择也清空
        cler(state) {
            state.groupLoopList = []
            state.groupLoopList2 = null
        },
        // 路灯上的挂挂载设备是否显示开关策略
        Distinguish(state, res) {　
            state.distribution = res
            if (res == "单灯控制器" || res == 0 || res == 1) {
                state.Distinguish = true
            } else {
                state.Identification = res
                state.Distinguish = false

            }
        },
        // 用来判断是显示回路控制还是路灯控制
        mount(state, res) {
            state.mount = res == 2 ? '回路控制' : '单灯控制器'
        }
    },
    getters: {},
    actions: {
        grouplist(context, prams) {

            $http.get(`/api/threesuns/map/group/get`, {
                params: {
                    groupName: prams[0],
                    imcType: prams[1]
                }
            }).then(res => {
                context.commit('loop_groupList', res.data.data)
            }).catch(err => {
                console.log(err);
            })
        },
        // 钉子展示
        loopList(context, prams) {
            $http.get(`/api/threesuns/map/group/elecBoxMap/get`, {
                params: {
                    groupId: context.state.PacketLoopID,
                }
            }).then(res => {

                context.commit('resLoopList', res.data.data)
            }).catch(err => {
                console.log(err);
            })
        },
        loopList2(context, prams) {
            $http.get(`/api/threesuns/map/group/elecBox/get`, {
                params: {
                    elecBoxName: context.state.d_search,
                    groupId: context.state.PacketLoopID,
                    page: context.state.pages,
                    size: 2
                }
            }).then(res => {
                context.commit('resLoopList2', res.data.data)
                context.commit('total', res.data.total)
                context.commit('setPage')
            }).catch(err => {
                console.log(err);
            })
        }
    }
}